package uva.asimov.asimovtrainner;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

public class ExportXML extends Activity {

	
	private DataBaseManager manager;
	private Cursor cursor;
	private SimpleCursorAdapter adapter;

	private ListView listaEntrenamientos;
	private Button btnExportarYcompartir;
	private Button btnSeleccionarTodo;
	
	private static final String ASIMOV=MainActivity.class.getSimpleName();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_export_xml);

	    Log.d(ASIMOV, "...:::...0");
		
		listaEntrenamientos= (ListView) findViewById(R.id.listaEntrenamientos);
		
		final String[] from = new String[]{manager.CN_DESCRIPCION,manager.CN_FECHA};
        int[] to = new int[] {android.R.id.text1, android.R.id.text2};
        
        manager = new DataBaseManager(this);
        Log.d(ASIMOV, "Antes de cursor");
        cursor = manager.cargarCursor();
        adapter = new SimpleCursorAdapter(this,android.R.layout.two_line_list_item, cursor, from, to,0);
        listaEntrenamientos.setAdapter(adapter);
        final int numEntrenos=cursor.getCount();
        //final boolean seleccionado[] = null;
        Log.d(ASIMOV, "...:::...1");
        for (int i=0; i<numEntrenos;i++){
        	//seleccionado[i]=false;
        }
        Log.d(ASIMOV, "...:::...2");
        listaEntrenamientos.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				//CharArrayBuffer buffer = null;
				/*if (seleccionado[position]=false){
					seleccionado[position]=true;
					listaEntrenamientos.setBackgroundColor(Color.GREEN);
				}
				else if(seleccionado[position]=true){
					seleccionado[position]=false;
				}*/
				Log.d(ASIMOV,"----::::::::__--"+numEntrenos);
				
			}
		});
        
       
	
	
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.export_xml, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
